package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.UserInfoMapper;
import com.gxa.p2p.mapper.UserLockStatusMapper;
import com.gxa.p2p.pojo.UserInfo;
import com.gxa.p2p.pojo.UserLockStatus;
import com.gxa.p2p.service.UserLockStatusService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @author Longlin_Feng
 * @date 2020/8/5
 */
@Service
public class UserLockStatusServiceImpl implements UserLockStatusService {

  @Resource private UserInfoMapper userInfoMapper;
  @Resource private UserLockStatusMapper userLockStatusMapper;

  /**
   * 根据用户id修改用户锁定状态:正常/锁定
   *
   * @param userInfo 用户基本信息
   * @param userLockStatus 目标锁定状态
   * @return boolean 成功/失败
   */
  @Override
  public boolean setUserLockStatus(UserInfo userInfo, UserLockStatus userLockStatus) {

    // 通过传入的userInfo基本信息查询用户userId
    userInfo = userInfoMapper.selectUserId(userInfo);
    // 把userId注入userLockStatus
    userLockStatus.setUserId(userInfo.getUserId());

    return userLockStatusMapper.updateByUserId(userLockStatus) > 0;
  }
}
